package com.micro.user.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 乘客实体类
 * 
 * @author micro
 * @since 1.0.0
 */
@Data
@TableName("passenger_info")
public class Passenger {

    /**
     * 乘客ID
     */
    @TableId(value = "passenger_id", type = IdType.AUTO)
    private Long passengerId;

    /**
     * 用户ID
     */
    @TableField("user_id")
    private Long userId;

    /**
     * 乘客姓名
     */
    @TableField("passenger_name")
    private String passengerName;

    /**
     * 身份证号
     */
    @TableField("id_card_number")
    private String idCardNumber;

    /**
     * 乘客类型：0-成人,1-儿童,2-学生,3-军人等特殊群体
     */
    @TableField("passenger_type")
    private Integer passengerType;

    /**
     * 性别：0-女,1-男
     */
    @TableField("gender")
    private Integer gender;

    /**
     * 出生日期
     */
    @TableField("birth_date")
    private LocalDate birthDate;

    /**
     * 手机号
     */
    @TableField("phone_number")
    private String phoneNumber;

    /**
     * 状态：true-正常,false-禁用
     */
    @TableField("active")
    private Boolean active;

    /**
     * 创建时间
     */
    @TableField("create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    private LocalDateTime updateTime;

    /**
     * 乘客类型枚举
     */
    public enum PassengerType {
        ADULT(0, "成人"),
        CHILD(1, "儿童"),
        STUDENT(2, "学生"),
        SPECIAL(3, "特殊群体");

        private final int code;
        private final String description;

        PassengerType(int code, String description) {
            this.code = code;
            this.description = description;
        }

        public int getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 性别枚举
     */
    public enum Gender {
        FEMALE(0, "女"),
        MALE(1, "男");

        private final int code;
        private final String description;

        Gender(int code, String description) {
            this.code = code;
            this.description = description;
        }

        public int getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }

    /**
     * 计算年龄
     */
    public int getAge() {
        if (birthDate == null) {
            return 0;
        }
        LocalDate now = LocalDate.now();
        int age = now.getYear() - birthDate.getYear();
        if (now.getMonthValue() < birthDate.getMonthValue() || 
            (now.getMonthValue() == birthDate.getMonthValue() && now.getDayOfMonth() < birthDate.getDayOfMonth())) {
            age--;
        }
        return age;
    }

    /**
     * 判断是否为儿童
     */
    public boolean isChild() {
        return getAge() < 12;
    }

    /**
     * 判断是否为学生
     */
    public boolean isStudent() {
        return passengerType == PassengerType.STUDENT.getCode();
    }
}
